package com.aricksm.xuan.activaty02;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import java.lang.reflect.Method;

public class PopWindowActivity extends Activity {

    PopupWindow popupWindow;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popwindow_main);

        findViewById(R.id.btn_pop_window).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                popupWindow.showAsDropDown(v);
                popupWindow.showAtLocation(PopWindowActivity.this.getWindow().getDecorView(),
                        Gravity.CENTER, 0, 0);
            }
        });


        View view = LayoutInflater.from(this).inflate(R.layout.pop_window, null);
        ((TextView) view.findViewById(R.id.tv_title)).setText("标题");
        ((TextView) view.findViewById(R.id.tv_msg)).setText("这里是popwindow显示的消息内容");
        view.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "您点击了确定按钮", Toast.LENGTH_SHORT).show();
                popupWindow.dismiss();
            }
        });
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "您点击了取消按钮", Toast.LENGTH_SHORT).show();
                popupWindow.dismiss();
            }
        });


        popupWindow = new PopupWindow(view, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT);

        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setFocusable(true);


    }

}
